package com.example.saifly.Pop;

import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.callback.ItemDragAndSwipeCallback;
import com.chad.library.adapter.base.listener.OnItemSwipeListener;
import com.codbking.widget.DatePickDialog;
import com.codbking.widget.OnSureLisener;
import com.codbking.widget.bean.DateType;
import com.example.common.Activity;
import com.example.common.Application.MyApplication;
import com.example.common.OSS.OssHelper;
import com.example.common.Retrofit.RetrofitHelper;
import com.example.saifly.Model.AdviceEquipment;
import com.example.saifly.Model.AdviceExercise;
import com.example.saifly.Model.AdviceMedicine;
import com.example.saifly.R;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.Body;
import retrofit2.http.Headers;
import retrofit2.http.POST;

public class PopNursingActivity extends Activity{
    private SharedPreferences sp= MyApplication.getContext().getSharedPreferences("config", Context.MODE_PRIVATE);

    //录入医嘱
    RecyclerView rvMedicine;
    RecyclerView rvExercise;
    RecyclerView rvEquipment;

    List<MedicineItem> medicineItemList;
    List<ExerciseItem> exerciseItemList;
    List<EquipmentItem> equipmentItemList;

    private ImageView ivMedicineadd;     //添加Item图标
    private ImageView ivExerciseadd;
    private ImageView ivEquipmentadd;
    private Button btCommit,btTakePicture;    //确认键,拍照上传
    private ImageView ivResultPicture;         //上传医嘱图片
    private String pictureUrl = ""; //上传图片地址
    private LocalMedia localPath;
    private String ossPath;

    //三个类的适配器
    MyAdapterExercise myAdapterExercise;
    MyAdapterEquipment myAdapterEquipment;
    MyAdapterMedicine myAdapterMedicine;

    //医嘱转今日计划
    private List<AdviceMedicine> adviceMedicineList;    //每日计划的list
    private List<AdviceExercise> adviceExerciseList;
    private List<AdviceEquipment> adviceEquipmentList;
    private List<DailyPlan> dailyPlanList;

    protected int getContentLayoutId() {
        return R.layout.activity_pop_edit_nursing;
    }

    //屏蔽返回键，因为医嘱应为必录
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK ){
                return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private class DailyPlan{
        private Integer planId;
        private String content;
        private Date time;
        private String patientPhone;
        DailyPlan(Integer planId,String content,Date time,String patientPhone){
            this.planId = planId;
            this.content = content;
            this.time = time;
            this.patientPhone = patientPhone;
        }

        DailyPlan(String content,Date time,String patientPhone){
            this.content = content;
            this.time = time;
            this.patientPhone = patientPhone;
        }

        public Integer getPlanId() {
            return planId;
        }

        public void setPlanId(Integer planId) {
            this.planId = planId;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public Date getTime() {
            return time;
        }

        public void setTime(Date time) {
            this.time = time;
        }

        public String getPatientPhone() {
            return patientPhone;
        }

        public void setPatientPhone(String patientPhone) {
            this.patientPhone = patientPhone;
        }
    }

    private class MedicineItem {
        String medicineName;
        String medicineTimes;
        String medicineStartTime;
        String medicineEndTime;

        public String getMedicineName() {
            return medicineName;
        }

        public void setMedicineName(String medicineName) {
            this.medicineName = medicineName;
        }

        public String getMedicineTimes() {
            return medicineTimes;
        }

        public void setMedicineTimes(String medicineTimes) {
            this.medicineTimes = medicineTimes;
        }

        public String getMedicineStartTime() {
            return medicineStartTime;
        }

        public void setMedicineStartTime(String medicineStartTime) {
            this.medicineStartTime = medicineStartTime;
        }

        public String getMedicineEndTime() {
            return medicineEndTime;
        }

        public void setMedicineEndTime(String medicineEndTime) {
            this.medicineEndTime = medicineEndTime;
        }

        MedicineItem(String medicineName, String medicineTimes, String medicineStartTime, String medicineEndTime){
            this.medicineName=medicineName;
            this.medicineTimes=medicineTimes;
            this.medicineStartTime=medicineStartTime;
            this.medicineEndTime=medicineEndTime;
        }
        @Override
        public String toString() {
            return "MedicineItem{" +
                    "medicineName='" + medicineName + '\'' +
                    ", medicineTimes='" + medicineTimes + '\'' +
                    ", medicineStartTime='" + medicineStartTime + '\'' +
                    ", medicineEndTime='" + medicineEndTime + '\'' +
                    '}';
        }
    }

    private class ExerciseItem {
        String exerciseName;
        String exerciseTimes;
        String exerciseStartTime;
        String exerciseEndTime;

        ExerciseItem(String exerciseName,String exerciseTimes,String exerciseStartTime,String exerciseEndTime){
            this.exerciseTimes=exerciseTimes;
            this.exerciseName=exerciseName;
            this.exerciseStartTime=exerciseStartTime;
            this.exerciseEndTime=exerciseEndTime;
        }

        public String getExerciseName() {
            return exerciseName;
        }

        public void setExerciseName(String exerciseName) {
            this.exerciseName = exerciseName;
        }

        public String getExerciseTimes() {
            return exerciseTimes;
        }

        public void setExerciseTimes(String exerciseTimes) {
            this.exerciseTimes = exerciseTimes;
        }

        public String getExerciseStartTime() {
            return exerciseStartTime;
        }

        public void setExerciseStartTime(String exerciseStartTime) {
            this.exerciseStartTime = exerciseStartTime;
        }

        public String getExerciseEndTime() {
            return exerciseEndTime;
        }

        public void setExerciseEndTime(String exerciseEndTime) {
            this.exerciseEndTime = exerciseEndTime;
        }
    }

    private class EquipmentItem{
        String equipmentName;
        String equipmentId;
        String equipmentStartTime;
        String equipmentEndTime;
        String equipmentLength;

        EquipmentItem(String equipmentName,String equipmentId,String equipmentStartTime,String equipmentEndTime,String equipmentLength){
            this.equipmentName=equipmentName;
            this.equipmentId=equipmentId;
            this.equipmentStartTime=equipmentStartTime;
            this.equipmentEndTime=equipmentEndTime;
            this.equipmentLength=equipmentLength;
        }

        public String getEquipmentName() {
            return equipmentName;
        }

        public void setEquipmentName(String equipmentName) {
            this.equipmentName = equipmentName;
        }

        public String getEquipmentId() {
            return equipmentId;
        }

        public void setEquipmentId(String equipmentId) {
            this.equipmentId = equipmentId;
        }

        public String getEquipmentStartTime() {
            return equipmentStartTime;
        }

        public void setEquipmentStartTime(String equipmentStartTime) {
            this.equipmentStartTime = equipmentStartTime;
        }

        public String getEquipmentEndTime() {
            return equipmentEndTime;
        }

        public void setEquipmentEndTime(String equipmentEndTime) {
            this.equipmentEndTime = equipmentEndTime;
        }

        public String getEquipmentLength() {
            return equipmentLength;
        }

        public void setEquipmentLength(String equipmentLength) {
            this.equipmentLength = equipmentLength;
        }
    }

    //初始化三个列表，初始都有一个Item
    private void  initMedicineItem(){
        medicineItemList.clear();
        MedicineItem item = new MedicineItem("","","点击录入时间","点击录入时间");
        medicineItemList.add(item);
    }

    private void  initExerciseItem(){
        exerciseItemList.clear();
        ExerciseItem item = new ExerciseItem("","","点击录入时间","点击录入时间");
        exerciseItemList.add(item);
    }

    private void  initEquipmentItem(){
        equipmentItemList.clear();
        EquipmentItem item = new EquipmentItem("","","点击录入时间","点击录入时间","点击录入时间");
        equipmentItemList.add(item);
    }

    //recyclerView右滑删除
    OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() {
        @Override
        public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int i) {

        }

        @Override
        public void clearView(RecyclerView.ViewHolder viewHolder, int i) {

        }

        @Override
        public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int i) {

        }

        @Override
        public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float v, float v1, boolean b) {

        }
    };

    //3个recyclerView配置
    private class MyAdapterMedicine extends BaseItemDraggableAdapter<MedicineItem, BaseViewHolder> {
        public MyAdapterMedicine(List<MedicineItem> medicineItemList) {
            super(R.layout.holder_nuring_medicine,medicineItemList);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder holder, MedicineItem item) {
            final int position=holder.getLayoutPosition();
            holder.setText(R.id.holder_nuring_medicine_name_et,medicineItemList.get(position).medicineName);
            holder.setText(R.id.holder_nuring_medicine_times_et,medicineItemList.get(position).medicineTimes);
            holder.setText(R.id.holder_nuring_medicine_starttime_et,medicineItemList.get(position).medicineStartTime);
            holder.setText(R.id.holder_nuring_medicine_endtime_et,medicineItemList.get(position).medicineEndTime);

            //监听RecyclerView和其子控件的点击事件
            holder.addOnClickListener(R.id.pop_edit_nuring_medicine_rv);
            holder.addOnClickListener(R.id.holder_nuring_medicine_starttime_et);
            holder.addOnClickListener(R.id.holder_nuring_medicine_endtime_et);

            setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    UpdateMedicineData();
                    switch (view.getId())
                    {
                        case R.id.holder_nuring_medicine_starttime_et:
                            Calendar startCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            medicineItemList.get(position).medicineStartTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterMedicine.notifyDataSetChanged();
                                        }
                                    },
                                    startCal.get(Calendar.YEAR),
                                    startCal.get(Calendar.MONTH),
                                    startCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                        case R.id.holder_nuring_medicine_endtime_et:
                            Calendar endCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            medicineItemList.get(position).medicineEndTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterMedicine.notifyDataSetChanged();
                                        }
                                    },
                                    endCal.get(Calendar.YEAR),
                                    endCal.get(Calendar.MONTH),
                                    endCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                    }
                }
            });
        }
    }

    private class MyAdapterExercise extends BaseItemDraggableAdapter<ExerciseItem,BaseViewHolder>{
        public MyAdapterExercise(List<ExerciseItem> exerciseItemList) {
            super(R.layout.holder_nuring_exercise,exerciseItemList);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder holder, ExerciseItem item) {
            final int position=holder.getLayoutPosition();
            holder.setText(R.id.holder_nuring_exercise_name_et,exerciseItemList.get(position).exerciseName);
            holder.setText(R.id.holder_nuring_exercise_times_et,exerciseItemList.get(position).exerciseTimes);
            holder.setText(R.id.holder_nuring_exercise_starttime_et,exerciseItemList.get(position).exerciseStartTime);
            holder.setText(R.id.holder_nuring_exercise_endtime_et,exerciseItemList.get(position).exerciseEndTime);

            holder.addOnClickListener(R.id.pop_edit_nuring_exercise_rv);
            holder.addOnClickListener(R.id.holder_nuring_exercise_starttime_et);
            holder.addOnClickListener(R.id.holder_nuring_exercise_endtime_et);

            setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    UpdateExerciseData();
                    switch (view.getId())
                    {
                        case R.id.holder_nuring_exercise_starttime_et:
                            Calendar startCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            exerciseItemList.get(position).exerciseStartTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterExercise.notifyDataSetChanged();
                                        }
                                    },
                                    startCal.get(Calendar.YEAR),
                                    startCal.get(Calendar.MONTH),
                                    startCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                        case R.id.holder_nuring_exercise_endtime_et:
                            Calendar endCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            exerciseItemList.get(position).exerciseEndTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterExercise.notifyDataSetChanged();
                                        }
                                    },
                                    endCal.get(Calendar.YEAR),
                                    endCal.get(Calendar.MONTH),
                                    endCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                    }
                }
            });
        }
    }

    private class MyAdapterEquipment extends BaseItemDraggableAdapter<EquipmentItem,BaseViewHolder>{
        public MyAdapterEquipment(List<EquipmentItem> equipmentItemList) {
            super(R.layout.holder_nuring_equipment,equipmentItemList);
        }

        @Override
        protected void convert(@NonNull BaseViewHolder holder, EquipmentItem item) {
            final int position=holder.getLayoutPosition();

            holder.setText(R.id.holder_nuring_equipment_id_et,equipmentItemList.get(position).equipmentId);
            holder.setText(R.id.holder_nuring_equipment_name_et,equipmentItemList.get(position).equipmentName);
            holder.setText(R.id.holder_nuring_equipment_starttime_et,equipmentItemList.get(position).equipmentStartTime);
            holder.setText(R.id.holder_nuring_equipment_endtime_et,equipmentItemList.get(position).equipmentEndTime);
            holder.setText(R.id.holder_nuring_equipment_length_et,equipmentItemList.get(position).equipmentLength);

            holder.addOnClickListener(R.id.pop_edit_nuring_equipment_rv);
            holder.addOnClickListener(R.id.holder_nuring_equipment_starttime_et);
            holder.addOnClickListener(R.id.holder_nuring_equipment_endtime_et);
            holder.addOnClickListener(R.id.holder_nuring_equipment_length_et);

            setOnItemChildClickListener(new OnItemChildClickListener() {
                @Override
                public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                    UpdateEquipmentData();
                    switch (view.getId())
                    {
                        case R.id.holder_nuring_equipment_starttime_et:                                     //调用日历选择器
                            Calendar startCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            equipmentItemList.get(position).equipmentStartTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterEquipment.notifyDataSetChanged();
                                        }
                                    },
                                    startCal.get(Calendar.YEAR),
                                    startCal.get(Calendar.MONTH),
                                    startCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                        case R.id.holder_nuring_equipment_endtime_et:
                            Calendar endCal =  Calendar. getInstance();
                            new DatePickerDialog(PopNursingActivity.this,
                                    new DatePickerDialog.OnDateSetListener() {
                                        @Override
                                        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                                            equipmentItemList.get(position).equipmentEndTime=year + "-" + (month+1) + "-" + day;
                                            myAdapterEquipment.notifyDataSetChanged();
                                        }
                                    },
                                    endCal.get(Calendar.YEAR),
                                    endCal.get(Calendar.MONTH),
                                    endCal.get(Calendar.DAY_OF_MONTH)).show();
                            break;
                        case R.id.holder_nuring_equipment_length_et:                             //调用年月日-时分选择器，其中我们只选用时分选择器来为治疗仪器选择使用时长
                            DatePickDialog dialog = new DatePickDialog(PopNursingActivity.this);
                            try {
                                dialog.setStartDate(stringToDate("2019-12-12 00:00","yyyy-MM-dd HH:mm"));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            String format = "HH时mm分";               //设置显示的格式，yyyy-MM-dd HH:mm可自由更改

                            dialog.setTitle("选择仪器的使用时长");   //设置标题
                            dialog.setType(DateType.TYPE_HM);       //设置类型
                            dialog.setMessageFormat(format);        //设置消息体的显示格式，日期格式
                            //设置点击确定按钮回调
                            dialog.setOnSureLisener(new OnSureLisener() {
                                @Override
                                public void onSure(Date date) {
                                    equipmentItemList.get(position).equipmentLength = new SimpleDateFormat(format).format(date);
                                    myAdapterEquipment.notifyDataSetChanged();
                                }
                            });
                            dialog.show();
                            break;
                    }
                }
            });
        }
    }

    // strTime要转换的string类型的时间，formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日
    // HH时mm分ss秒，
    // strTime的时间格式必须要与formatType的时间格式相同
    public static Date stringToDate(String strTime, String formatType)  throws ParseException
    {
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = null;
        date = formatter.parse(strTime);
        return date;
    }

    @Override
    protected void init() {
        super.init();

        initItemList();     //初始化三个RecyclerView的Itemlist数据
        initMedicineItem(); //放一个数据
        initExerciseItem();
        initEquipmentItem();

        //添加适配器
        rvMedicine= findViewById(R.id.pop_edit_nuring_medicine_rv);
        RecyclerView.LayoutManager layoutManagerMedicine=new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        rvMedicine.setLayoutManager(layoutManagerMedicine);
        //创建myAdapterMedicine的DragAndSwipe操作的回调
        ItemDragAndSwipeCallback itemDragAndSwipeCallbackMedicine = new ItemDragAndSwipeCallback(myAdapterMedicine);
        //创建itemtouch的适配器
        ItemTouchHelper itemTouchHelperMedicine = new ItemTouchHelper(itemDragAndSwipeCallbackMedicine);
        itemTouchHelperMedicine.attachToRecyclerView(rvMedicine);
        //开启滑动删除
        myAdapterMedicine.enableSwipeItem();
        myAdapterMedicine.setOnItemSwipeListener(onItemSwipeListener);
        //设置rvMedicine的适配器
        rvMedicine.setAdapter(myAdapterMedicine);


        rvExercise= findViewById(R.id.pop_edit_nuring_exercise_rv);
        RecyclerView.LayoutManager layoutManagerExercise=new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        rvExercise.setLayoutManager(layoutManagerExercise);
        //创建myAdapterExercise的DragAndSwipe操作的回调
        ItemDragAndSwipeCallback itemDragAndSwipeCallbackExercise = new ItemDragAndSwipeCallback(myAdapterExercise);
        //创建itemtouch的适配器
        ItemTouchHelper itemTouchHelperExercise = new ItemTouchHelper(itemDragAndSwipeCallbackExercise);
        itemTouchHelperExercise.attachToRecyclerView(rvExercise);
        //开启滑动删除
        myAdapterExercise.enableSwipeItem();
        myAdapterExercise.setOnItemSwipeListener(onItemSwipeListener);
        //设置rvExercise的适配器
        rvExercise.setAdapter(myAdapterExercise);

        rvEquipment= findViewById(R.id.pop_edit_nuring_equipment_rv);
        RecyclerView.LayoutManager layoutManagerEquipment=new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL);
        rvEquipment.setLayoutManager(layoutManagerEquipment);
        //创建myAdapterEquipment的DragAndSwipe操作的回调
        ItemDragAndSwipeCallback itemDragAndSwipeCallbackEquipment = new ItemDragAndSwipeCallback(myAdapterEquipment);
        //创建itemtouch的适配器
        ItemTouchHelper itemTouchHelperEquipment = new ItemTouchHelper(itemDragAndSwipeCallbackEquipment);
        itemTouchHelperEquipment.attachToRecyclerView(rvEquipment);
        //开启滑动删除
        myAdapterEquipment.enableSwipeItem();
        myAdapterEquipment.setOnItemSwipeListener(onItemSwipeListener);
        //设置rvExercise的适配器
        rvEquipment.setAdapter(myAdapterEquipment);

        ivEquipmentadd=findViewById(R.id.pop_edit_nuring_equipment_add);
        ivExerciseadd=findViewById(R.id.pop_edit_nuring_exercise_add);
        ivMedicineadd=findViewById(R.id.pop_edit_nuring_medicine_add);

        DoAdd();                                                                                //添加三个添加键的监听事件

        btTakePicture = findViewById(R.id.pop_edit_nuring_commit_takepicture);
        btCommit= findViewById(R.id.pop_edit_nuring_commit_bt);
        ivResultPicture = findViewById(R.id.pop_edit_nuring_result_picture);
        Commit_info();
        TakePicture();
    }
    private void initItemList() {
        medicineItemList =new ArrayList<>();
        exerciseItemList =new ArrayList<>();
        equipmentItemList=new ArrayList<>();
        myAdapterEquipment=new MyAdapterEquipment(equipmentItemList);
        myAdapterMedicine=new MyAdapterMedicine(medicineItemList);
        myAdapterExercise=new MyAdapterExercise(exerciseItemList);
    }

    private void TakePicture() {
        btTakePicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TakePicture_info();
            }
        });
    }

    private void TakePicture_info() {
        PictureSelector.create(PopNursingActivity.this)
                .openGallery(PictureMimeType.ofImage())//选择图片资源
                .selectionMode(PictureConfig.SINGLE)//单选图片
                .previewImage(true)//可预览图片
                .isCamera(true)//可拍照
                .enableCrop(false)//允许裁剪
                .compress(true)//压缩
                .withAspectRatio(1, 1)//裁剪比1：1
                .hideBottomControls(false)//显示底部控制栏
                .isGif(false)//不显示gif图
                .freeStyleCropEnabled(true)//可拖拽裁剪框
                .circleDimmedLayer(true)//圆形裁剪框
                .showCropFrame(false)//圆形建议取消边框
                .minimumCompressSize(100)//图片如果小于100kb就不压缩
                .rotateEnabled(true)//可旋转
                .scaleEnabled(true)//可放大缩小
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    //此处设置拍照上传图片
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    // 图片、视频、音频选择结果回调
                    List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                    localPath = selectList.get(0);
                    // 例如 LocalMedia 里面返回四种path
                    // 1.media.getPath(); 为原图path
                    // 2.media.getCutPath();为裁剪后path，需判断media.isCut();是否为true  注意：音视频除外
                    // 3.media.getCompressPath();为压缩后path，需判断media.isCompressed();是否为true  注意：音视频除外
                    // 如果裁剪并压缩了，以取压缩路径为准，因为是先裁剪后压缩的
                    // 4.media.getAndroidQToPath();为Android Q版本特有返回的字段，此字段有值就用来做上传使用
                    if (localPath.isCompressed()) {
                        pictureUrl = localPath.getCompressPath();
                    } else if (localPath.isCut()) {
                        pictureUrl = localPath.getCutPath();
                    } else {
                        pictureUrl = localPath.getPath();
                    }
                    ivResultPicture.setVisibility(View.VISIBLE);
                    Glide.with(PopNursingActivity.this).load(pictureUrl).into(ivResultPicture);
                    break;
            }
        }
    }

    //监听确认按钮的点击事件
    private void Commit_info(){
        btCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击确认键,将recyclerView的数据保存在分别的List中
                UpdateMedicineData();
                UpdateExerciseData();
                UpdateEquipmentData();
                if(medicineItemList.size() < 1 || exerciseItemList.size() < 1 || equipmentItemList.size() < 1){                  //先保证每个RecyclerView至少有一项
                    Toast.makeText(PopNursingActivity.this,"请每个分类至少录入一项内容",Toast.LENGTH_SHORT).show();
                }
                else if(Isreasonable() == false){                                                                               //判断是否有未输入的数据
                }
                else {
                    try {
                        if(IsStartMoreEnd()){                                                                           //再判断起始日期是否大于结束日期
                        }
                        else{
                            GeneratePlan();     //根据输入的内容生成每日计划
//                            开启线程，向后端发送请求，将三个类和每日计划上传
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    MedicineExerciseEquipmentPlanInfo();
                                    SendDocAdvPic();
                                }
                            }).start();
                            //点击确定之后，本页面销毁，即直接finish()该activity
                            finish();
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    private void GeneratePlan() throws ParseException {
        //1、获取医嘱信息
        //2、根据次数生成固定时间
        //3、根据三种类型调用不同的方法
        GenerateMedicine();
        GenerateExercise();
        GenerateEquipment();
        GenerateDailyPlan();
        Toast.makeText(PopNursingActivity.this,"笨笨的机器人已自动为您生成护理计划，请自行前往今日事项自行修改使用时间",Toast.LENGTH_LONG).show();
    }

    private void GenerateDailyPlan() throws ParseException {
        dailyPlanList = new ArrayList<>();
        String content;
        Date time = null;
        String patientPhone = sp.getString("uid","12345678910");

        //对用药类，分一天1-6次
        //1对应12点，2对应8,20点，3对应8，14，20点，4对应8，12，16，20点，5对应8，11，14，17，20点，6对应8，10.30，13，15.30，18，20.30
        for(int i = 0; i < medicineItemList.size(); i++){
            content = medicineItemList.get(i).medicineName;
            switch (Integer.valueOf(medicineItemList.get(i).medicineTimes))
            {
                case 1:
                    time = stringToDate("12:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 2:
                    time = stringToDate("08:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("20:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 3:
                    time = stringToDate("08:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("14:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("20:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 4:
                    time = stringToDate("08:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("12:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("16:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("20:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 5:
                    time = stringToDate("08:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("11:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("14:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("17:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("20:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 6:
                    time = stringToDate("08:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("10:30","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("13:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("15:30","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("18:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("20:30","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                default:
                    break;
            }
            Log.d("123", "GenerateDailyPlan: "+time);
        }

        //运动类，分一天1-3次
        //1对应14点，2对应10，19点，3对应10，14.30，19点
        for(int i = 0; i < exerciseItemList.size(); i++){
            content = exerciseItemList.get(i).exerciseName;
            switch (Integer.valueOf(exerciseItemList.get(i).exerciseTimes))
            {
                case 1:
                    time = stringToDate("14:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 2:
                    time = stringToDate("10:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("19:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                case 3:
                    time = stringToDate("10:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("14:30","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    time = stringToDate("19:00","HH:mm");
                    dailyPlanList.add(new DailyPlan(content,time,patientPhone));
                    break;
                default:
                    break;
            }
            Log.d("123", "GenerateDailyPlan: "+time);
        }

        //治疗仪器类，只有使用时长，没有使用次数
        //每天14点提醒
        for(int i = 0; i < equipmentItemList.size(); i++){
            content = equipmentItemList.get(i).equipmentName;
            time  = stringToDate("19:00","HH:mm");
            Log.d("123", "GenerateDailyPlan: "+time);
            dailyPlanList.add(new DailyPlan(content,time,patientPhone));
        }
//        Toast.makeText(MainPageActivity.this,""+dailyPlanList.get(0).time,Toast.LENGTH_LONG).show();
    }

    private void GenerateEquipment() throws ParseException {
        adviceEquipmentList = new ArrayList<>();
        for(int i = 0; i < equipmentItemList.size(); i++){
            AdviceEquipment adviceEquipment = new AdviceEquipment();

            adviceEquipment.setPatientPhone(sp.getString("uid","12345678910"));
            adviceEquipment.setName(equipmentItemList.get(i).equipmentName);
            adviceEquipment.setStartTime(stringToDate(equipmentItemList.get(i).equipmentStartTime,"yyyy-MM-dd"));
            adviceEquipment.setEndTime(stringToDate(equipmentItemList.get(i).equipmentEndTime,"yyyy-MM-dd"));
            adviceEquipment.setDeviceId(equipmentItemList.get(i).equipmentId);
            adviceEquipment.setLengthOfUse(equipmentItemList.get(i).equipmentLength);

            adviceEquipmentList.add(adviceEquipment);
        }
    }

    private void GenerateExercise() throws ParseException {
        adviceExerciseList = new ArrayList<>();
        for(int i = 0; i < exerciseItemList.size(); i++){
            AdviceExercise adviceExercise = new AdviceExercise();

            adviceExercise.setPatientPhone(sp.getString("uid","12345678910"));
            adviceExercise.setName(exerciseItemList.get(i).exerciseName);
            adviceExercise.setStartTime(stringToDate(exerciseItemList.get(i).exerciseStartTime,"yyyy-MM-dd"));
            adviceExercise.setEndTime(stringToDate(exerciseItemList.get(i).exerciseEndTime,"yyyy-MM-dd"));
            adviceExercise.setTimes(Integer.valueOf(exerciseItemList.get(i).exerciseTimes));

            adviceExerciseList.add(adviceExercise);
        }
    }

    private void GenerateMedicine() throws ParseException {
        adviceMedicineList = new ArrayList<>();
        for(int i = 0; i < medicineItemList.size(); i++){
            AdviceMedicine adviceMedicine = new AdviceMedicine();

            adviceMedicine.setPatientPhone(sp.getString("uid","12345678910"));
            adviceMedicine.setName(medicineItemList.get(i).medicineName);
            adviceMedicine.setStartTime(stringToDate(medicineItemList.get(i).medicineStartTime,"yyyy-MM-dd"));
            adviceMedicine.setEndTime(stringToDate(medicineItemList.get(i).medicineEndTime,"yyyy-MM-dd"));
            adviceMedicine.setTimes(Integer.valueOf(medicineItemList.get(i).medicineTimes));

            adviceMedicineList.add(adviceMedicine);
        }
    }

    //通过String转Date，判断起始日期是否大于结束日期，大于返回true
    private boolean IsDateMore(String start,String end) throws ParseException {
        Date startDate = new SimpleDateFormat("yyyy-mm-dd").parse(start);
        Date endDate = new SimpleDateFormat("yyyy-mm-dd").parse(end);
        if(startDate.compareTo(endDate) == 1) return true;
        return false;
    }

    private boolean IsStartMoreEnd() throws ParseException {
        for(int i = 0; i < medicineItemList.size(); i++){
            if(IsDateMore(medicineItemList.get(i).medicineStartTime,medicineItemList.get(i).medicineEndTime) == true){
                Toast.makeText(PopNursingActivity.this,"第"+(i+1)+"项用药类结束日期应晚于开始日期",Toast.LENGTH_LONG).show();
                return true;
            }
        }
        for(int i = 0; i < exerciseItemList.size(); i++){
            if(IsDateMore(exerciseItemList.get(i).exerciseStartTime,exerciseItemList.get(i).exerciseEndTime) == true){
                Toast.makeText(PopNursingActivity.this,"第"+(i+1)+"项运动类结束日期应晚于开始日期",Toast.LENGTH_LONG).show();
                return true;
            }
        }
        for(int i = 0; i < equipmentItemList.size(); i++){
            if(IsDateMore(equipmentItemList.get(i).equipmentStartTime,equipmentItemList.get(i).equipmentEndTime) == true){
                Toast.makeText(PopNursingActivity.this,"第"+(i+1)+"项治疗仪器类结束日期应晚于开始日期",Toast.LENGTH_LONG).show();
                return true;
            }
        }
        return false;
    }

    private boolean Isreasonable(){
        for(int i = 0; i < medicineItemList.size(); i++){
            if(medicineItemList.get(i).medicineName == "" || medicineItemList.get(i).medicineTimes == "" || medicineItemList.get(i).medicineStartTime == "点击录入时间" || medicineItemList.get(i).medicineEndTime == "点击录入时间"){
                Toast.makeText(PopNursingActivity.this,"请正确输入用药类的第"+(i+1)+"项数据",Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        for(int i = 0; i < exerciseItemList.size(); i++){
            if(exerciseItemList.get(i).exerciseName == "" || exerciseItemList.get(i).exerciseTimes == "" || exerciseItemList.get(i).exerciseStartTime == "点击录入时间" || exerciseItemList.get(i).exerciseEndTime == "点击录入时间"){
                Toast.makeText(PopNursingActivity.this,"请正确输入运动类的第"+(i+1)+"项数据",Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        for (int i = 0; i < equipmentItemList.size(); i++){
            if(equipmentItemList.get(i).equipmentName == "" || equipmentItemList.get(i).equipmentId == "" || equipmentItemList.get(i).equipmentStartTime == "点击录入时间" || equipmentItemList.get(i).equipmentEndTime == "点击录入时间"
                    || equipmentItemList.get(i).equipmentLength == "点击录入时间" || equipmentItemList.get(i).equipmentLength.equals("00时00分")){
                Toast.makeText(PopNursingActivity.this,"请正确输入治疗仪器类的第"+(i+1)+"项数据",Toast.LENGTH_SHORT).show();
                return false;
            }
        }

        for(int i = 0; i < medicineItemList.size(); i++){
            if(Integer.valueOf(medicineItemList.get(i).medicineTimes) > 6 || Integer.valueOf(medicineItemList.get(i).medicineTimes) < 1){
                Toast.makeText(PopNursingActivity.this,"请正确输入第"+(i+1)+"项药物的使用次数，理应为1-6次之间，若有疑问请联系客服",Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        for(int i = 0; i < exerciseItemList.size(); i++){
            if(Integer.valueOf(exerciseItemList.get(i).exerciseTimes) > 3 || Integer.valueOf(exerciseItemList.get(i).exerciseTimes) < 1){
                Toast.makeText(PopNursingActivity.this,"请正确输入第"+(i+1)+"项运动的使用次数，理应为1-3次之间，若有疑问请联系客服",Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        return true;
    }

    //将Medicine的RecyclerView的数据保存在其MedicineList中
    private void UpdateMedicineData(){
        for(int i=0;i<medicineItemList.size();i++) {
            View view = rvMedicine.getChildAt(i);                                               //i为当前行的定位
            EditText medicinename = view .findViewById(R.id.holder_nuring_medicine_name_et);
            medicineItemList.get(i).medicineName=medicinename.getText().toString();

            EditText medicinetimes = view .findViewById(R.id.holder_nuring_medicine_times_et);
            medicineItemList.get(i).medicineTimes=medicinetimes.getText().toString();

            TextView medicinestarttime = view .findViewById(R.id.holder_nuring_medicine_starttime_et);
            medicineItemList.get(i).medicineStartTime=medicinestarttime.getText().toString();

            TextView medicineendtime = view .findViewById(R.id.holder_nuring_medicine_endtime_et);
            medicineItemList.get(i).medicineEndTime=medicineendtime.getText().toString();
        }
    }

    //将Exercise的RecyclerView的数据保存在其ExerciseList中
    private void UpdateExerciseData(){
        for(int i=0;i<exerciseItemList.size();i++) {
            View tempView = rvExercise.getChildAt(i);                                           //i为当前行的定位
            EditText exerciseName = tempView .findViewById(R.id.holder_nuring_exercise_name_et);
            exerciseItemList.get(i).exerciseName=exerciseName.getText().toString();

            EditText exerciseTimes = tempView .findViewById(R.id.holder_nuring_exercise_times_et);
            exerciseItemList.get(i).exerciseTimes=exerciseTimes.getText().toString();

            TextView exerciseStartTime = tempView .findViewById(R.id.holder_nuring_exercise_starttime_et);
            exerciseItemList.get(i).exerciseStartTime=exerciseStartTime.getText().toString();

            TextView exerciseEndTime = tempView .findViewById(R.id.holder_nuring_exercise_endtime_et);
            exerciseItemList.get(i).exerciseEndTime=exerciseEndTime.getText().toString();
        }
    }

    //将Equipment的RecyclerView的数据保存在其EquipmentList中
    private void UpdateEquipmentData(){
        for(int i=0;i<equipmentItemList.size();i++) {
            View tempView = rvEquipment.getChildAt(i);                                      //i为当前行的定位
            EditText equipmentname = tempView .findViewById(R.id.holder_nuring_equipment_name_et);
            equipmentItemList.get(i).equipmentName=equipmentname.getText().toString();

            EditText equipmentid = tempView .findViewById(R.id.holder_nuring_equipment_id_et);
            equipmentItemList.get(i).equipmentId=equipmentid.getText().toString();

            TextView equipmentStartTime = tempView .findViewById(R.id.holder_nuring_equipment_starttime_et);
            equipmentItemList.get(i).equipmentStartTime=equipmentStartTime.getText().toString();

            TextView equipmentEndTime = tempView.findViewById(R.id.holder_nuring_equipment_endtime_et);
            equipmentItemList.get(i).equipmentLength = equipmentEndTime.getText().toString();

            TextView equipmentLength = tempView.findViewById(R.id.holder_nuring_equipment_length_et);
            equipmentItemList.get(i).equipmentLength = equipmentLength.getText().toString();
        }
    }

    private void DoAdd() {
        ivMedicineadd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateMedicineData();

                MedicineItem item = new MedicineItem("", "", "点击录入时间","点击录入时间");
                medicineItemList.add(item);
                myAdapterMedicine.notifyDataSetChanged();
            }
        });

        ivExerciseadd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateExerciseData();

                ExerciseItem item = new ExerciseItem("", "", "点击录入时间","点击录入时间");
                exerciseItemList.add(item);
                myAdapterExercise.notifyDataSetChanged();
            }
        });

        ivEquipmentadd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateEquipmentData();

                EquipmentItem item = new EquipmentItem("", "", "点击录入时间", "点击录入时间","点击录入时间");
                equipmentItemList.add(item);
                myAdapterEquipment.notifyDataSetChanged();
            }
        });
    }

    //网络请求接口,上传医嘱信息
    private interface ApiDoctorAdvice
    {
        @Headers({"Content-Type:application/json"})                             //大家都不变
        @POST("/plan/submitDoctorAdvice")                                    //后端给的路径
        Call<ResponseBody> MedicineExerciseEquipmentPlanInfo(@Body JSONObject jsonObject);
    }

    private void MedicineExerciseEquipmentPlanInfo() {
        //将三个类和每日计划List转String
        JSONObject jsonObject = new JSONObject();

        String adviceMedicineJson = JSON.toJSONString(adviceMedicineList);      //用药类
        jsonObject.put("medicineInfomation", adviceMedicineJson);

        String adviceExerciseJson = JSON.toJSONString(adviceExerciseList);      //运动类
        jsonObject.put("exerciseInfomation", adviceExerciseJson);

        String adviceEquipmentJson = JSON.toJSONString(adviceEquipmentList);    //治疗仪器类
        jsonObject.put("treatmentEquipment", adviceEquipmentJson);

        String dailyPlanJson = JSON.toJSONString(dailyPlanList);                //每日计划类
        jsonObject.put("dailyPlan", dailyPlanJson);

//        Log.d("123", "medicineJson:" + adviceMedicineJson);
//        Log.d("123","exerciseJson:"+adviceExerciseJson);
//        Log.d("123","equipmentJson:"+adviceEquipmentJson);
//        Log.d("123","dailyPlanJson:"+dailyPlanJson);
        Log.d("123", "MedicineExerciseEquipmentPlanInfo: "+jsonObject.toJSONString());

        RetrofitHelper retrofitHelper=new RetrofitHelper();     //大家都一样
        Retrofit retrofit=retrofitHelper.getRetrofit();

        ApiDoctorAdvice apiDoctorAdvice = retrofit.create(ApiDoctorAdvice.class);

        Call<ResponseBody> call = apiDoctorAdvice.MedicineExerciseEquipmentPlanInfo(jsonObject);
        final Response<ResponseBody> response;
        try {
            response = call.execute();
            if(response.body() != null){
                String jsonResponse = response.body().string();
                JSONObject result=JSON.parseObject(jsonResponse);
                if(result.getInteger("code")!=null&&result.getInteger("code")==1){
                    //这里放正常流程操作
                }
                else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(PopNursingActivity.this, "网络出现异常", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }

        } catch (IOException e) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(PopNursingActivity.this, "服务器在开小差儿", Toast.LENGTH_SHORT).show();
                }
            });
            e.printStackTrace();
        }
    }

    //上传医嘱图片
    private interface ApiDoctorAdvicePicture{
        @Headers({"Content-Type:application/json"})                             //大家都不变
        @POST("/plan/submitDoctorAdvicePicture")                                    //后端给的路径
        Call<ResponseBody> SendDocAdvPic(@Body JSONObject jsonObject);
    }

    private void SendDocAdvPic(){
        if(pictureUrl == "") return ;
        //无医嘱图片则不发送，非必选

        JSONObject jsonObject = new JSONObject();

        String uploadUrl = OssHelper.uploadImage(this,pictureUrl);

        String doctorAdvicePicture = JSON.toJSONString(uploadUrl);
        jsonObject.put("doctorAdvicePicture",doctorAdvicePicture);

        RetrofitHelper retrofitHelper=new RetrofitHelper();     //大家都一样
        Retrofit retrofit=retrofitHelper.getRetrofit();

        ApiDoctorAdvicePicture apiDoctorAdvicePicture = retrofit.create(ApiDoctorAdvicePicture.class);

        Call<ResponseBody> call = apiDoctorAdvicePicture.SendDocAdvPic(jsonObject);
        final Response<ResponseBody> response;
        try {
            response = call.execute();
            if(response.body() != null){
                String jsonResponse = response.body().string();
                JSONObject result=JSON.parseObject(jsonResponse);
                if(result.getInteger("code")!=null&&result.getInteger("code")==1){
                    //这里放正常流程操作
                }
                else{
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(PopNursingActivity.this, "网络出现异常", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            }

        } catch (IOException e) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(PopNursingActivity.this, "服务器在开小差儿", Toast.LENGTH_SHORT).show();
                }
            });
            e.printStackTrace();
        }
    }
}

